package cn.edu.nju.software.grapheditor;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;

import cn.edu.nju.software.grapheditor.shape.Shape;
/**@author smy*/
//Completed on May 21th
//Modified on May 28th
public class Drawing {
    Color curcolor;
    ArrayList <Shape> Shapes;
	public Drawing(Color initialColor) {
		this.curcolor=initialColor;
		this.Shapes=new ArrayList <Shape>();
	}
	
	public Shape getFrontmostContainer(Point p) {
		Shape ans=null;
		for(int i=0;i<Shapes.size();i++){
			if(Shapes.get(i).containsPoint(p))ans=Shapes.get(i);
		}
		return ans;
	}
	
	public void draw(Graphics g) {
		for(int i=0;i<Shapes.size();i++)
			Shapes.get(i).draw(g);
	}
	
	public void addshape(Shape s){
		this.Shapes.add(s);
	}
	
	public void addshape(Shape s,int index){
	    this.Shapes.add(index,s);	
	}
	
	public void delshape(Shape s){
		this.Shapes.remove(s);
	}
	
	public Color getColor(){
		return this.curcolor;
	}
	
	public void setColor(Color s){
		this.curcolor=s;
	}
	
	public int GetIndex(Shape s){
		return this.Shapes.indexOf(s);
	}
}
